<?php

namespace app\controllers;

use app\logic\GroupLogic;
use yii\web\HttpException;
use app\components\Controller;
use yii\db\StaleObjectException;

/**
 * 组织控制器
 */
class GroupController extends Controller
{
    protected function verbs()
    {
        return [
            'index' => ['GET'],
            'create' => ['POST'],
            'update' => ['POST'],
            'delete' => ['POST'],
            'get-tree-list' => ['GET'],
            'get-drop-list' => ['GET'],
            'get-info' => ['GET'],
        ];
    }

    /**
     * 组织 首页
     * @return array
     */
    public function actionIndex()
    {
        return GroupLogic::index();
    }

    /**
     * 创建 组织
     * @throws HttpException
     */
    public function actionCreate()
    {
        return GroupLogic::create(getParams());
    }

    /**
     * 编辑 组织
     * @throws HttpException
     */
    public function actionUpdate()
    {
        return GroupLogic::update(getParams());
    }

    /**
     * 删除 组织
     * @throws \Throwable
     * @throws StaleObjectException
     */
    public function actionDelete()
    {
        return GroupLogic::delete(getParams());
    }

    /**
     * 组织 & 部门 树形 （ 用户首页调用 ）
     * @return array[]
     */
    public function actionGetTreeList()
    {
        return GroupLogic::getTreeList();
    }

    /**
     * 组织 下拉列表
     * @return array
     */
    public function actionGetDropList()
    {
        return GroupLogic::getDropList();
    }

    /**
     * 组织 编辑时的信息
     * @return array
     * @throws HttpException
     */
    public function actionGetInfo()
    {
        return GroupLogic::getInfo(getParams());
    }

    public function actionGetTreeForItemData()
    {
        return GroupLogic::getTreeForItemData();
    }
}
